<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<title>上传游戏</title>
<%@ include file="../common/dev_head.jsp"%>
</head>
<body>
<script type="text/javascript">
		$(document).ready(
					function(){
						$("#mainmenu li").removeClass("active-menu");
						$("#mainmenu>li").eq(1).addClass("active-menu");
					}
		);
		
		//文件上传
		function upload(){
			/*var name=$("#name").val();
			//var type=$("#type").val();
			var introduce=$("#introduce").val();
			var img=$("#img").val();
			var file=$("#file").val();
			*/
			if($("#name").val()==""||$("#introduce")==""||$("#img")==""||$("#file")==""){
				alert("请输入必填内容");
				return;
			}
			var formData=new FormData($("#game")[0]);
		
			$.ajax({
				url:getContextPath()+"/developer/upload",
				type:"POST",
				data:formData,
				async: false,  
		        cache: false,  
		        contentType: false,  
		        processData: false,  
				success:function(result){
					switch(result){
						case "1":
							alert("上传成功,请等待管理员审核!");
							window.location.href=getContextPath()+"/developer/progress";
							break;
						case "2":
							alert("上传文件不能为空,请重新选择!");
							break;
						case "3":
							alert("文件保存失败,请稍后重试!");
							break;
						case "4":
							alert("游戏保存失败,请稍后重试!");
							break;
					}
				}
				
			});
		}
		
		
		//截取文件名
		function getFileName(file){
	        var arr = file.split('\\');//通过\分隔字符串，成字符串数组
	        return arr[arr.length-1];//取最后一个，就是文件名
	    }
</script>	

	<div id="wrapper">
			<%@ include file="./dev_title.jsp" %>
		<!-- /. NAV SIDE  -->
		<div id="page-wrapper">
			<div id="page-inner">
				<div class="row">
					<div class="col-lg-12">
						<div class="panel panel-default">
							<div class="panel-heading" style="text-align: center;">请编辑要上传的游戏信息</div>
							<div class="panel-body" style="text-align: center;">
								<div class="row">
									<div class="col-lg-12">
										<form role="form" enctype="multipart/form-data" id="game">
											<div class="form-group">
												<label>游戏名称</label> <input id="name" name="name" class="form-control" required>
											</div>
											<div class="form-group">
												<label>游戏类型</label> 
												<select id="type" class="form-control" name="type">
													<c:if test="${!empty types }">
														<c:forEach items="${types }" var="t">
															<option value="${t.typeId }">${t.typeName }</option>
														</c:forEach>
													</c:if>
												</select>
											</div>
											<div class="form-group">
												<label>游戏介绍</label>
												<textarea id="introduce" name="introduce" class="form-control" rows="3"></textarea>
											</div>
											<div class="form-group">
												<label>游戏封面</label> <input id="img" name="img" type="file" multiple="multiple">
											</div>
											<div class="form-group" style="wight=400px;height=400px;">
												<img id="show" src="">
											</div>
											<div class="form-group">
												<label>游戏内容</label> <input id="file" name="file" type="file" multiple="multiple">
											</div>
											<button type="button" class="btn btn-default" onclick="upload()">提交</button>
                                        	<button type="reset" class="btn btn-default">取消</button>
										</form>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- /. PAGE INNER  -->
			</div>
			<!-- /. PAGE WRAPPER  -->
		</div>
	</div>
		<!-- /. WRAPPER  -->
</body>
</html>
<script>

$("#img").change(function(){  
     var objUrl = getObjectURL(this.files[0]) ;  
     if (objUrl) {  
       // 在这里修改图片的地址属性  
       $("#show").attr("src", objUrl) ;  
     }  
   }) ; 
//获取上传文件的url
function getObjectURL(file) {  
 var url = null ;   
 // 下面函数执行的效果是一样的，只是需要针对不同的浏览器执行不同的 js 函数而已  
 if (window.createObjectURL!=undefined) { // basic  
   url = window.createObjectURL(file) ;  
 } else if (window.URL!=undefined) { // mozilla(firefox)  
   url = window.URL.createObjectURL(file) ;  
 } else if (window.webkitURL!=undefined) { // webkit or chrome  
   url = window.webkitURL.createObjectURL(file) ;  
 }  
 return url ;  
} 
</script>
<script src="${pageContext.request.contextPath}/js/functions.js"></script>